<!DOCTYPE html>
<html   xmlns="http://www.w3.org/1999/xhtml"
        xmlns:th="http://www.w3.org/1999/xhtml"
>
<head lang="en">
    <meta charset="UTF-8"/>
    <meta content="text/html"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <title>Thymeleaf test</title>
</head>

<body>
<h1 th:text="${host}">Hello World</h1>

<br/>
普通操作
<br/>
<hr/>
<br/>


<p th:with="isOk=${1}"> <span>赋值：th:with="isOk=${1}"</span></p>

<p>对象操作</p>
<div th:object="${user}">
    <p>Username:<input type="text" name="username" value="username" th:value="*{username}" /></p>
    <p>Password:<span th:text="*{password}">password</span></p>
    <!-- @{/order/details(orderId=${o.id})} -->
    <p>Url:<a href="index.html" th:href="@{/sayHello}">Say Hello</a></p>
</div>

<br/>
格式转换
<br/>
<hr/>
<br/>

<div>
    <p>Price:<span th:text="${#numbers.formatDecimal(12.232,1,2)}"></span></p>
    <p>Times:<span th:text="${#dates.format(time,'yyyy-MM-dd')}"></span></p>
</div>

<br/>
表单
<br/>
<hr />
<br/>

<!-- 实体User 必须要有无参的构造方法 -->
<form th:object="${user}" th:method="post" th:action="@{/submit}" method="post">
    <p style="width: 100%;"><span style="width: inherit 100px;">id:</span><input type="text" name="id" th:field="*{id}" /></p>
    <p><span style="width: 100px;">username:</span><input type="text" name="username" th:field="*{username}" /></p>
    <p><span style="width: 100px;">password:</span><input type="text" name="password" th:field="*{password}" /></p>
    <p><input type="submit" value="submit" /></p>
</form>

<br/>
迭代
<br/>
<hr />
<br/>

<table>
    <thead>
        <tr>
            <td>id</td>
            <td>name</td>
            <td>pass</td>
        </tr>
    </thead>
    <!--th:remove="all-but-first"-->
    <tbody >
        <tr th:each="user,userStat:${userList}">
            <td th:text="${userStat.count}">id</td>
            <td th:text="${user.username}">name</td>
            <td th:text="${user.password}">pass</td>
        </tr>
    </tbody>
</table>

<br/>
条件分支
<br/>
<hr />
<br/>

<p >


    If:
    <!-- < : lt   &  > : gt  -->
    <span th:if="${100 gt 10}" th:text="${isOk}">if test</span>

    <select class='form-control' name="proficiency">
        <option >权限</option>
        <option th:if="${user.username eq 'show'}" th:selected="selected">一般</option>
        <option th:if="${user.username eq 'admin'}" th:selected="selected">系统</option>
        <option th:if="${user.username eq 'super'}" th:selected="selected">超级</option>
    </select>

    <br/>

    Switch:
    <select th:field="${user.gender}" th:switch="${user.gender.toString()}" data-required="true">
        <option value="male" th:case="${'male'}" th:selected="selected" >男</option>
        <option value="female" th:case="${'female'}" th:selected="selected" >女</option>
        <option value="" >请选择</option>
    </select>

</p>

<br/>
国际化
<br/>
<hr />
<br/>

<span>
    1.3.+版本要增加：<br />
    @Bean<br />
	public ResourceBundleMessageSource messageSource(){<br />
		ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();<br />
		messageSource.setUseCodeAsDefaultMessage(true);<br />
		messageSource.setFallbackToSystemLocale(false);<br />
		messageSource.setBasenames("messages","common_messages");<br />
		messageSource.setDefaultEncoding("UTF-8");<br />
		messageSource.setCacheSeconds(2);<br />
		return messageSource;<br />
	}<br />
</span>

<p>
    <!-- 表达式对象 用 '#' 作为前缀 -->
    <span th:text="${#locale}">当前环境</span>
    <br />
    <span th:text="${#locale.getCountry()}">当前国家</span>
    <br />
    <span th:utext="#{home.welcome}">国际化</span>
    <br />



</p>



</body>
</html>